package com.twq.lambda;

/**
 * @author twq
 * @date 2021/8/20 17:21
 */

public class TestLambda1 {


    //  2  静态内部类
    static class Like2 implements ILike {

        @Override
        public void lambda() {
            System.out.println("i like lambda2");
        }
    }


    public static void main(String[] args) {
        Like like = new Like();
        like.lambda();

        Like2 like2 = new Like2();
        like2.lambda();


//       3 局部内部类
        class Like3 implements ILike {

            @Override
            public void lambda() {
                System.out.println("i like lambda3");
            }
        }

        Like3 like3 = new Like3();
        like3.lambda();


//        4匿名内部类，没有类的名称，必须借助接口或者父类
        ILike like4 = new ILike() {
            @Override
            public void lambda() {
                System.out.println("i like lambda4");
            }
        };
        like4.lambda();


////        用lambda简化
//        like5 = () -> {
//            System.out.println("i like lambda5");
//        };
//        like5.lambda();
//    }
//
    }
}

//定义一个函数接口
interface ILike {
    void lambda();
}

//实现类
 class Like implements ILike {

    @Override
    public void lambda() {
        System.out.println("i like lambda1");
    }
}